﻿@model CloudStorageLight.Core.Web.AppBlobDirectoryVM
@{
    Layout = null;
    var groupSelectList = ((List<SelectListItem>)ViewData["grouplist"]);
    var idx = 0;
    var cloudAccount = CloudStorageLight.Core.BlobService.GetCurrentCloudAccount();
}
<div style="height:100%;width:100%;overflow:hidden;" class="metro">
    @using (Html.BeginForm("UpdateBlobItem", "Helper", FormMethod.Post, new { id = "blobItemDetailForm" }))
    {
        <div style="width:100%;height:380px;" class="tab-control" data-role="tab-control">


            <ul class="tabs">
                <li class="active"><a href="#_page_1">@(CloudStorageLight.Core.Web.ViewMessages.MsgAccessRights)</a></li>
                <li><a href="#_page_2">@(CloudStorageLight.Core.Web.ViewMessages.MsgAccessDetail)</a></li>
            </ul>

            <div class="frames">
                <div class="frame" id="_page_1" style="display: block;overflow:auto;width:100%;height:320px;">

                    @Html.Hidden("id", Model.Path)

                    <table style="width:100%;">
                        <tr>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgInUse</th>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgRole</th>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgReadAccess</th>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgWriteAccess</th>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgModifyAccess</th>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgControlAccess</th>
                        </tr>
                        @for (int i = 0; i < Model.AccessTokens.Count; i++)
                        {
                            if (Model.AccessTokens[i].Role == "everyone" || Model.AccessTokens[i].Role == "guest" || Model.AccessTokens[i].Role == "users")
                            {
                                continue;
                            }
                            <tr>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + i.ToString() + "].InUse", true)
                                </td>
                                <td>
                                    @Model.AccessTokens[i].Role
                                    @Html.Hidden("AccessTokens[" + i.ToString() + "].Role", Model.AccessTokens[i].Role)
                                </td>
                                <td>
                                    @Html.CheckBoxFor(x => x.AccessTokens[i].CanRead)
                                </td>
                                <td>
                                    @Html.CheckBoxFor(x => x.AccessTokens[i].CanWrite)
                                </td>
                                <td>
                                    @Html.CheckBoxFor(x => x.AccessTokens[i].CanModify)
                                </td>
                                <td>
                                    @Html.CheckBoxFor(x => x.AccessTokens[i].CanControl)
                                </td>
                            </tr>
                            {
                                idx++;
                            }
                        }

                        @for (int i = idx; i < idx + 3; i++)
                        {
                            <tr>
                                <td></td>
                                <td>
                                    @Html.TextBox("AccessTokens[" + i.ToString() + "].Role", "", new { @class = "userRoleList" })
                                </td>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + i.ToString() + "].CanRead")
                                </td>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + i.ToString() + "].CanWrite")
                                </td>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + i.ToString() + "].CanModify")
                                </td>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + i.ToString() + "].CanControl")
                                </td>
                            </tr>
                        }
                        @{
                        int usersIdx = idx + 3;
                        var users = Model.AccessTokens.FirstOrDefault(x => x.Role == "users");
                        }
                        <tr>
                            <td rowspan="2">
                                @Html.CheckBox("AccessTokens[" + usersIdx.ToString() + "].InUse", users != null, new { id = "usersRoleCheckBox" })
                            </td>
                            <td>
                                @CloudStorageLight.Core.Web.ViewMessages.MsgUsersRole
                                @Html.Hidden("AccessTokens[" + usersIdx.ToString() + "].Role", "users")
                            </td>
                            <td>
                                @Html.CheckBox("AccessTokens[" + usersIdx.ToString() + "].CanRead", users != null && users.CanRead)
                            </td>
                            <td>
                                @Html.CheckBox("AccessTokens[" + usersIdx.ToString() + "].CanWrite", users != null && users.CanWrite)
                            </td>
                            <td>
                                @Html.CheckBox("AccessTokens[" + usersIdx.ToString() + "].CanModify", users != null && users.CanModify)
                            </td>
                            <td>
                                @Html.CheckBox("AccessTokens[" + usersIdx.ToString() + "].CanControl", users != null && users.CanControl)
                            </td>
                        </tr>
                        <tr>
                            <td colspan="5">
                                @Html.TextAreaFor(x => x.UsersRole, new { placeholder = CloudStorageLight.Core.Web.ViewMessages.MsgUsersRoleDescription, style = "width:100%;" })
                            </td>
                        </tr>

                        @{
                        int everyoneIdx = usersIdx + 1;
                        var eveyone = Model.AccessTokens.FirstOrDefault(x => x.Role == "everyone");
                        }
                        <tr>
                            <td>
                                @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].InUse", eveyone != null)
                            </td>
                            <td>
                                @CloudStorageLight.Core.Web.ViewMessages.MsgEveryoneRole
                                @Html.Hidden("AccessTokens[" + everyoneIdx.ToString() + "].Role", "everyone")
                            </td>
                            <td>
                                @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].CanRead", eveyone != null && eveyone.CanRead)
                            </td>
                            <td>
                                @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].CanWrite", eveyone != null && eveyone.CanWrite)
                            </td>
                            <td>
                                @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].CanModify", eveyone != null && eveyone.CanModify)
                            </td>
                            <td>
                                @Html.CheckBox("AccessTokens[" + everyoneIdx.ToString() + "].CanControl", eveyone != null && eveyone.CanControl)
                            </td>
                        </tr>
                        @{
                        int guestIdx = everyoneIdx + 1;
                        var guest = Model.AccessTokens.FirstOrDefault(x => x.Role == "guest");
                        }
                        @if (cloudAccount.CanUseGuestAccount)
                        {
                            <tr>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + guestIdx.ToString() + "].InUse", guest != null)
                                </td>
                                <td>
                                    @CloudStorageLight.Core.Web.ViewMessages.MsgGuestPublic
                                    @Html.Hidden("AccessTokens[" + guestIdx.ToString() + "].Role", "guest")
                                </td>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + guestIdx.ToString() + "].CanRead", guest != null && guest.CanRead)
                                </td>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + guestIdx.ToString() + "].CanWrite", guest != null && guest.CanWrite)
                                </td>
                                <td>
                                    @Html.CheckBox("AccessTokens[" + guestIdx.ToString() + "].CanModify", guest != null && guest.CanModify)
                                </td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                        }
                    </table>

                </div>
                <div class="frame" id="_page_2" style="display: block;overflow:auto;width:100%;height:320px;">

                    <table>
                        @if (cloudAccount.CanFullTextSearch)
                        {
                            <tr>
                                <th>@CloudStorageLight.Core.Web.ViewMessages.MsgIsSearched</th>
                                <td>@Html.DropDownListFor(x => x.SearchMode, Model.SearchModeList, new { style = "width:200px;" })<span style="margin-left:10px;margin-right:10px;">@(Model.SearchModeValue)</span></td>
                                <td>
                                    @if (Model.User.IsAdmin)
                                    {
                                        <button type="button" id="startCrawl">@(CloudStorageLight.Core.Web.ViewMessages.MsgCrawl)</button>
                                    }
                                </td>
                            </tr>
                        }
                        @if (cloudAccount.CanUseBackupFunction)
                        {
                            <tr>
                                <th>@CloudStorageLight.Core.Web.ViewMessages.MsgIsBackup</th>
                                <td>@Html.DropDownListFor(x => x.BackupMode, Model.BackupModeList, new { style = "width:200px;" })<span style="margin-left:10px;margin-right:10px;">@(Model.BackupModeValue)</span></td>
                                <td></td>
                            </tr>
                        }
                        <tr>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgFileProtectedMode</th>
                            <td>@Html.DropDownListFor(x => x.ProtectedMode, Model.ProtectedModeList, new { style = "width:200px;" })<span style="margin-left:10px;margin-right:10px;">@(Model.ProtectedModeValue)</span></td>
                            <td></td>
                        </tr>
                        @if (cloudAccount.CanUseAutoPassword)
                        {
                            <tr>
                                <th>@CloudStorageLight.Core.Web.ViewMessages.MsgFilePasscode</th>
                                <td><spn>@Html.TextBoxFor(x => x.FilePasscode, new { @class = "password" })<i id="open-icon" class="icon-eye"></i></spn></td>
                                <td></td>
                            </tr>
                        }
                        @if (CloudStorageLight.Core.SystemSettings.Instance.UseRMS && cloudAccount.CanUseRMS)
                        {
                            <tr>
                                <th>@CloudStorageLight.Core.Web.ViewMessages.MsgRmsTemplateId</th>
                                <td>@Html.DropDownListFor(x => x.RmsTemplateId, Model.RmsTemplateIdList, new { style = "width:200px;" })<div style="margin-left:10px;margin-right:10px;">@(Model.RmsTemplateIdValue)</div></td>
                                <td></td>
                            </tr>
                        }
                        <tr>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgCaseInsensitive</th>
                            <td>@Html.DropDownListFor(x => x.CaseInsensitive, Model.CaseInsensitiveList, new { style = "width:200px;" })<span style="margin-left:10px;margin-right:10px;">@(Model.CaseInsensitiveValue)</span></td>
                            <td></td>
                        </tr>
                        <tr>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgMaxHistorySize</th>
                            <td>@Html.TextBoxFor(x => x.MaxHistorySize, new { style = "width:50px;" })<span style="margin-left:10px;margin-right:10px;">@(Model.MaxHistorySizeValue)</span></td>
                            <td></td>
                        </tr>
                        <tr>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgDecryptableFileOnly</th>
                            <td>@Html.DropDownListFor(x => x.DecryptableFileOnly, Model.DecryptableFileOnlyList, new { style = "width:200px;" })<span style="margin-left:10px;margin-right:10px;">@(Model.DecryptableFileOnlyValue)</span></td>
                            <td></td>
                        </tr>
                        <tr>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgDownloadFromOriginalUrl</th>
                            <td>@Html.DropDownListFor(x => x.DownloadFromOriginalUrl, Model.DownloadFromOriginalUrlList, new { style = "width:200px;" })<span style="margin-left:10px;margin-right:10px;">@(Model.DownloadFromOriginalUrlValue)</span></td>
                            <td></td>
                        </tr>
                        <tr>
                            <th>@CloudStorageLight.Core.Web.ViewMessages.MsgUploadableFileExtension</th>
                            <td><spn>@Html.TextBoxFor(x => x.UploadableFileExtension)</spn><div style="margin-left:10px;margin-right:10px;">@(Model.UploadableFileExtensionValue)</div></td>
                            <td></td>
                        </tr>

                    </table>
                </div>
            </div>

        </div>

        <button id="blobItemDetailOkButton" type="button" onclick="CloudStorageLight.StorageController.updateFolder();">@(CloudStorageLight.Core.Web.ViewMessages.MsgSave)</button>
        <button type="button" onclick="CloudStorageLight.StorageController.closeUpdateFolderDialog();">@(CloudStorageLight.Core.Web.ViewMessages.MsgCancel)</button>
    }

    <script type="text/javascript">
        $(function () {
            $('.userRoleList').unbind().autocomplete({
                source: '@Url.Action("UserRoleList")',
                minLength: 2
            });

            $('.password').attr('type', 'password');
            $('#open-icon').unbind().hover(function () {
                $('.password').attr('type', 'text');
            }, function () {
                $('.password').attr('type', 'password');
            });
            $("#startCrawl").unbind().click(function () {
                CloudStorageLight.StorageController.startCrawl("@(Model.Path)");
            });
            $(".tab-control").tabcontrol();
        });

    </script>
</div>
